﻿<!DOCTYPE html>
<html lang="zh">
<head>
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">
    <meta name="renderer" content="webkit">
    <meta http-equiv="CurrData.Type" content="text/html; charset=utf-8" />
    <meta charset="utf-8" />
    <title>Index </title>
    <link href="/favicon.ico" rel="shortcut icon" type="image/x-icon" />
    <meta name="viewport" content="width=device-width" />

    <link href="/js/kd/styles/kendo.common.min.css" rel="stylesheet" />
    <link href="/js/kd/styles/kendo.blueopal.min.css" rel="stylesheet" />
    <link href="/js/fa/css/font-awesome.min.css" rel="stylesheet" />
    <link href="/js/site.css?t=20221031" rel="stylesheet" />

    <script src="/js/kd/jquery.min.js"></script>
    <script src="/js/kd/kendo.web.min.js"></script>
    <script src="/js/kd/kendo.aspnetmvc.min.js"></script>
    <script src="/js/kd/cultures/kendo.culture.zh-CN.min.js"></script>
    <script src="/js/kd/messages/kendo.messages.zh-CN.min.js"></script>
    <script src="/js/kd/jszip.min.js"></script>

    
    <script src="/js/kendo_stdefine.js?t=1"></script>
    <script src="/js/site50.js"></script>

    <script src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.17.0/xlsx.full.min.js"></script>


</head>
<body>
    <style>
        body, html {
            width: 100%;
            height: 100%;
            color: rgb(101, 173, 235);
            font-size: 12px;
            background-color: rgba( 13,20,84,1);
        }

        textarea {
            height: 60px !important;
        }

        .tdLabel75 {
            padding: 5px;
        }

        @media screen and (max-width: 1400px) {
            body, html {
                font-size: 10px;
            }
        }

        .flexcol {
            flex-direction: column;
            display: flex;
            justify-content: center;
            align-items: center;
        }

        .flexrow {
            display: flex;
            justify-content: center;
            align-items: center;
        }

        .bgfull {
            background-size: 100% 100%;
        }

        :root {
            --var_color_B: rgb(11,203,237)
        }

        .colorB {
            color: var(--var_color_B);
        }

        .bgB {
            background-color: var(--var_color_B);
        }

        .myBtn {
            cursor: pointer;
            pointer-events: all;
        }

            .myBtn:hover {
                animation: myBtnScale 1s ease-in-out infinite alternate;
            }


        @keyframes myBtnScale {
            from {
                scale: 1;
            }

            to {
                scale: 1.2;
            }
        }
    </style>
    <style>
        .k-window {
            background-image: url(/img/windowbg.png) !important;
            background-size: 100% 100%;
            padding: 5px;
        }

        .k-window-content {
            overflow-y: auto;
        }

        .k-window-titlebar {
            background: linear-gradient(135deg, rgba(30, 144, 255, 0.8), rgba(0, 0, 139, 0.8)) !important;
            margin-top: -30px !important;
        }

        .k-window-iframecontent {
            height: calc(100% - 5px);
        }

        .k-window-actions {
            top: 8px !important;
        }
    </style>

    <style>
        body {
        }
        a.k-pager-refresh.k-link {
            display: block;
        }
        .k-splitter {
            position: absolute;
            left: 5px;
            top: 5px;
            width: calc(100% - 12px);
            height: calc(100% - 12px);
        }

        .k-splitbar-horizontal {
            width: 0px !important;
        }

        .tdValue {
            flex: 1;
        }

        i {
            cursor: pointer;
        }
    </style>

    <div id="divSplitter" data-role="splitter"
         data-panes="[
                { collapsible: false, resizable: false,  size: '245px' },
                { collapsible: false, resizable: false }
             ]"
         style="">
        <div id="left-pane" style="overflow:hidden;overflow-y:auto;">
            <div id="toolbarCenter" style="height:40px;line-height:40px;margin-bottom:2px;border-bottom: 1px solid #23549C;background:#14346a;font-family:'Microsoft YaHei'" class="flexrow">

                <div style="flex:1;">
                    <ul data-role="buttongroup"
                        data-index="1"
                        data-bind="  events: { select: buttongroup_Select }">

                        <li>协议</li>
                        <li>模拟</li>
                        <li>日志</li>

                    </ul>
                </div>
                <div style="width:20px;color:#5999D4;">
                    <a id="btnAdd" style="cursor:pointer;" title="添加" onclick="btnAdd_Click()"><i class="fa fa-lg fa-plus"></i></a>
                </div>
                <div style="width:20px;color:#5999D4;"> </div>

                <div style="width:20px;color:#5999D4;">
                    <a id="btnAddHost" style="cursor:pointer;" title="添加主机" onclick="AddSimHost()"><i class="fa fa-lg fa-address-book-o"></i></a>
                </div>

                <div style="width:20px;color:#5999D4;">

                    </div>
                    <div style="width:20px;color:#5999D4;">
                        <a id="btnDelete" style="cursor:pointer;" title="删除" onclick="btnDelete_Click()"><i class="fa fa-lg fa-trash"></i></a>
                    </div>




                </div>
            <div id="listView"></div>

            <div id="treeview"
                 data-role="treeview"
                 data-drag-and-drop="false"
                 data-text-field="text"
                 data-id-field="id"
                 data-spritecssclass-field="imageurl"
                 data-bind="source: treeData,
                    events: { change: treeNodeChange }"
                 style="flex-wrap: wrap;overflow-x:hidden;overflow-y:auto ;height:calc( 100% - 45px)">

            </div>


        </div>

        <div id="center" style="overflow: hidden;overflow-y:auto; ">



        </div>


    </div>



    <script>
        function myAjax(options) {
            if (options.win == undefined) {
                options.win = myGetTop();
            }
            if (options.async == undefined) options.async = true;
            if (!options.timeout) options.timeout = 30000;
            if (options.contentType == undefined) options.contentType = "application/json";
            if (options.type == undefined) options.type = "POST";
            if (options.contentType == "application/json") {
                if (typeof (options.data) != "string") {
                    options.data = JSON.stringify(options.data);
                }
            }
            if (options.Alert == undefined) options.Alert = true;
            var opt = {
                before: function () {
                    kendo.ui.progress($("body"), true);

                },
                after: function () {
                    kendo.ui.progress($("body"), false);
                },
                timeout: options.timeout,
                contentType: options.contentType,
                type: options.type,
                dataType: 'json',
                async: options.async,
                cache: false,
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    opt2.after();
                    if (options.Alert) {
                        if (textStatus == "timeout") {
                            myAlert("请求超时");
                        }
                        else {
                            myAlert('错误.:' + textStatus + " " + errorThrown);
                        }
                    }
                    else {
                        opt2.err({ C: "-1", M: "" + textStatus + " " + errorThrown });
                    }

                },
                err: function (r) {
                    myAlert('错误:' + r.Message);
                }
            }
            var opt2 = $.extend(true, {}, opt, options);
            opt2.success = function (r) {
                opt2.after();

                if (r.Code == "" || r.C == "") {
                    if (options.success) {
                        options.success(r);
                    }
                }
                else {
                    opt2.err(r);
                }
            }
            opt2.before();
            options.win.$.ajax(opt2);
        }
        myAjaxList = function (opt) {
            var oldsuccess = opt.success;
            opt.success = (r) => {
                for (var i = 0; i < r.Data.length; i++) {
                    r.Data[i].RowNo = i + 1;
                }
                oldsuccess(r);
            }
            myAjax(opt);
        }

        function newDataSource(opt) {
            //jq
            //getParam
            //url
            var pageSize = 20;
            if (opt.pageSize) {
                pageSize = opt.pageSize;
            }
            var dataSource = new kendo.data.DataSource({
                transport: {
                    read: function (options) {
                        if (opt.getParam) {
                            opt.getParam(options.data);
                        } 
                        var data = options.data;
                        myAjax({
                            url: opt.url,
                            data: data,
                            before: function () {
                                if (opt.opt) {
                                    kendo.ui.progress(obj.jq, true);
                                }
                            },
                            after: function () {
                                if (opt.opt) {
                                    kendo.ui.progress(obj.jq, true);
                                }
                            }, 
                            success: function (result) {
                                for (var i = 0; i < result.Data.Data.length; i++) {
                                    var o = result.Data.Data[i]
                                    o.RowNo = (data["page"] - 1) * data["pageSize"] + i + 1;
                                }
                                // notify the data source that the request succeeded
                                options.success(result.Data);
                            },
                            error: function (result) {
                                // notify the data source that the request failed
                                options.error(result);
                            }
                        });
                    }
                },
                batch: false,
                serverPaging: true,
                serverFiltering: true,
                serverSorting: true,
                schema: {
                    model: {
                        id: "Id",
                        fields: {
                            Id: { editable: false, nullable: true }

                        }
                    },
                    data: "Data",
                    total: "Total",
                },
                pageSize: pageSize
            });

            return dataSource;
        }
 
function isBitString(input) {
    // 使用正则表达式判断字符串是否只包含0和1
    return /^[01]+$/.test(input);
}
function isByteString(input) {
    // 使用正则表达式判断字符串是否是1到3位数字，且值在0-255之间
    return /^\d{1,3}$/.test(input) && parseInt(input) >= 0 && parseInt(input) <= 255;
}
function isUInt16String(input) {
    // 使用正则表达式判断字符串是否是1到5位数字，且值在0-65535之间
    return /^\d{1,5}$/.test(input) && parseInt(input) >= 0 && parseInt(input) <= 65535;
}
function isIntString(input) {
    // 使用正则表达式判断字符串是否是整数（可包含正负号）
    return /^[-+]?\d+$/.test(input);
}
function isFloatString(input) {
    // 使用正则表达式判断字符串是否是浮点数（可包含正负号和小数点）
    return /^[-+]?\d*\.?\d+$/.test(input);
}





    </script>
    <style>
        .lb_product2 {
            margin: 10px;
            line-height: 25px;
            border-bottom: 1px dashed #143c75;
            cursor: pointer;
        }

            .lb_product2:hover:not(.k-state-selected) {
                background: #18477f80 !important;
            }

        .k-listview {
            border: none;
        }

        .divtitle {
            height: 30px;
            background: #18477f80 !important;
            margin-top: 5px;
        }
    </style>

    <script type="text/x-kendo-template" id="detailTemplate">

    </script>
    <script>
        var viewModel = new kendo.data.ObservableObject({

            buttongroup_Select: function (e) {
                var buttonGroup = e.sender;
                var index = buttonGroup.current().index();
                switch (index) {
                    case 0:
                        var url = "/index.html";
                        break;
                    case 1:
                        var url = "/indexsim.html";
                        break;
                    case 2:
                        var url = "/indexlog.html";
                        break;
                }
                window.location.href = url;
            },
            treeNodeChange: function (e) {
                var treeView = $("#treeview").data("kendoTreeView");
                var nodedata = treeView.dataItem(treeView.select());
                if (!nodedata) {
                    $("#btnAdd").show();
                    $("#btnDelete").hide();
                    return;
                }
                 
               

                switch (nodedata.attrs2) {
                    case "A":
                        ShowProtocolSimDetail(nodedata);
                        if (nodedata.attrs1 == "串口") {
                            $("#btnAddHost").show();
                            $("#btnDelete").show();
                        } else {
                            $("#btnAddHost").hide();
                            $("#btnDelete").show();
                        }


                        break;//第一级
                    case "B":
                        ShowProtocolSimHostDetail(nodedata);

                        var p = treeView.parent(treeView.select());
                        var pdata = treeView.dataItem(p);
                        if (pdata.attrs1 == "串口") {
                            if (pdata.items.length > 1) {
                                $("#btnDelete").show();
                            } else {
                                $("#btnDelete").hide();
                            }
                            $("#btnAddHost").hide();

                        } else {
                            $("#btnAddHost").hide();
                            $("#btnDelete").hide();

                        }  

                        break;//第二级
                }
            },
            treeData: [],

        });
        var gridBaseOption = {
            autoBind: false,
            navigatable: true,
            pageable: false,
            editable: false,
            messages: $.extend(true, {}, KDGridmessages),
            sortable: true,
            selectable: "row",
            filterable: false,
        };


        var CurrData = {};
        function Init() {

            kendo.bind($("#divSplitter"), viewModel);



            GetTree("");
        }

        function GetTree(selid) {
            $("#center").html("");
            var tv = $("#treeview").data("kendoTreeView");

            myAjax({
                url: "/api/ProtocolSim/Tree",
                success: function (r) {

                    var ohy = kendo.observableHierarchy({
                        data: r.Data
                    });

                    viewModel.set("treeData", ohy);

                    if (selid) {

                        var di = tv.dataSource.get(selid);
                        var bar = tv.findByUid(di.uid);
                        tv.select(bar);
                    } else if (r.Data.length > 0) {
                        var selectedNode = tv.findByText(r.Data[0].text);
                        tv.select(selectedNode);
                    }

                }
            });
        };


        function closeWindow(sender) {
            var win = $(sender).closest(".k-window-content");
            win.data("kendoWindow").close();
        }
        function updown_Click(sender) {
            var obj = $(sender);
            var p = obj.closest(".divtitle");

            if (obj.hasClass("fa-chevron-up")) {
                obj.removeClass("fa-chevron-up");
                obj.addClass("fa-chevron-down");
                var nextElement = p[0].nextElementSibling; // 获取p的同级下一个元素

                $(nextElement).toggle();
            } else {
                obj.removeClass("fa-chevron-down");
                obj.addClass("fa-chevron-up");
                var nextElement = p[0].nextElementSibling; // 获取p的同级下一个元素
                $(nextElement).toggle();
            }
        }

        function btnAdd_Click() {

            var treeView = $("#treeview").data("kendoTreeView");
            var nodedata = treeView.dataItem(treeView.select());
            if (!nodedata) {
                AddSim();
                return;
            }
            AddSim();
            switch (nodedata.attrs2) {
                case "A":
                    AddSim();
                    break;//第一级
                case "B":
                    var p = treeView.parent(treeView.select());
                    var pdata = treeView.dataItem(p);
                    if (pdata.attrs1 == "串口") {
                        AddHost(pdata);
                    }                     
                    break;//第二级
            }

        }
        function AddSimHost() {
          var treeView = $("#treeview").data("kendoTreeView");
            var nodedata = treeView.dataItem(treeView.select());
            if (!nodedata) {
                AddSim();
                return;
            } 
                AddHost(nodedata);
                       
        }
        
        function btnDelete_Click() {
            var treeView = $("#treeview").data("kendoTreeView");
            var nodedata = treeView.dataItem(treeView.select());
            if (!nodedata) {
                
                return;
            }
            switch (nodedata.attrs2) {
                case "A":
                    DeleteSim();
                    break;//第一级
                case "B":
                    var p = treeView.parent(treeView.select());
                    var pdata = treeView.dataItem(p);
                    if (pdata.attrs1 == "串口"&&pdata.items.length>1) {
                        DeleteHost();
                    }
                    break;//第二级
            }

        }

         






    </script>

    <!--基本信息-->
    <div id="divSimAdd" style="display:none;">
        <form id="form1">
            <div class="flexrow">
                <div class="tdLabel75">模拟名称</div>
                <div class="tdValue">
                    <input class="k-textbox" required data-bind="value:m.Name"
                           placeholder="模拟名称" />
                </div>
                <div style="width:20px;"></div>
            </div>

            <div class="flexrow">
                <div class="tdLabel75">协议</div>
                <div class="tdValue">
                    <input id="ProtocolDefineId" data-role="dropdownlist"
                           data-value-primitive="true"
                           data-text-field="Name"
                           data-value-field="Id"
                           data-autoBind="true"
                           data-height="300"
                           data-bind="source:ProtocolDs,value:m.ProtocolDefineId" />
                </div>
                <div style="width:20px;"></div>
            </div>

            <div class="flexrow">
                <div class="tdLabel75">模拟方式</div>
                <div class="tdValue">
                    <input id="Mode" data-role="dropdownlist"
                           data-value-primitive="true"
                           data-text-field="Name"
                           data-value-field="Name"
                           data-autoBind="true"
                           data-height="300"
                           data-bind="source:ModeDs,value:m.Mode,events:{change:Mode_Chnge}" />
                </div>
                <div style="width:20px;"></div>
            </div>

            <div id="divCK">
                <!-- 新增串口配置部分 -->
                <div class="flexrow">
                    <div class="tdLabel75">串口选择</div>
                    <div class="tdValue">

                        <input id="ComPort" data-role="dropdownlist"
                               data-value-primitive="true"
                               data-text-field="Name"
                               data-value-field="Name"
                               data-autoBind="true"
                               data-height="300"
                               data-bind="source:ComPortDs,value:m.ComPort " />

                    </div>
                    <div style="width:20px;"></div>
                </div>

                <div class="flexrow">
                    <div class="tdLabel75">波特率</div>
                    <div class="tdValue">

                        <input id="BaudRate" data-role="dropdownlist"
                               data-value-primitive="true"
                               data-text-field="Name"
                               data-value-field="Name"
                               data-autoBind="true"
                               data-height="300"
                               data-bind="source:BaudRateDs,value:m.BaudRate " />

                    </div>
                    <div style="width:20px;"></div>
                </div>

                <div class="flexrow">
                    <div class="tdLabel75">校验方式</div>
                    <div class="tdValue">

                        <input id="Parity" data-role="dropdownlist"
                               data-value-primitive="true"
                               data-text-field="Name"
                               data-value-field="Name"
                               data-autoBind="true"
                               data-height="300"
                               data-bind="source:ParityDs,value:m.Parity " />

                    </div>
                    <div style="width:20px;"></div>
                </div>

                <div class="flexrow">
                    <div class="tdLabel75">数据位</div>
                    <div class="tdValue">

                        <input id="DataBits" style="width:150px;"
                               data-role="numerictextbox"
                               data-min="0"
                               data-max="255"
                               data-format="N0"
                               data-bind="value:m.DataBits" />

                    </div>
                    <div style="width:20px;"></div>
                </div>

                <div class="flexrow">
                    <div class="tdLabel75">停止位</div>
                    <div class="tdValue">

                        <input id="StopBits" data-role="dropdownlist"
                               data-value-primitive="true"
                               data-text-field="Name"
                               data-value-field="Name"
                               data-autoBind="true"
                               data-height="300"
                               data-bind="source:StopBitsDs,value:m.StopBits " />

                    </div>
                    <div style="width:20px;"></div>
                </div>
                <!-- 结束串口配置部分 -->
            </div>

            <div id="divIP">
                <div class="flexrow">
                    <div class="tdLabel75">端口</div>
                    <div class="tdValue">
                        <input id="Port" style="width:150px;"
                               data-role="numerictextbox"
                               data-min="0"
                               data-max="65555"
                               data-format="N0"
                               data-bind="value:m.Port" />
                    </div>
                    <div style="width:20px;"></div>
                </div>
            </div>


            <div class="flexrow" data-bind="visible:IsAdd">
                <div class="tdLabel75">主机号</div>
                <div class="tdValue">

                    <input id="HostId" style="width:150px;"
                           data-role="numerictextbox"
                           data-min="1"
                           data-max="255"
                           data-format="N0"
                           data-bind="value:m.HostId" />

                </div>
                <div style="width:20px;"></div>
            </div>

        </form>


        <div style="height:20px;">

        </div>

        <div class="flexrow">
            <div style="flex:1;"></div>
            <div style="width:100px;">
                <a href="javascript:SimSave();" class="k-button" style="width:80px;" accesskey="S">

                    <span style="text-decoration:underline;">S</span>
                    确定
                </a>
            </div>

            <div style="width:100px;">
                <a href="javascript:;" onclick="closeWindow(this);" class="k-button" style="width:80px;" accesskey="C">

                    <span style="text-decoration:underline;">C</span>
                    取消
                </a>
            </div>

            <div style="flex:1;"></div>
        </div>
    </div>
    <script>
        var viewModelJbxx = new kendo.data.ObservableObject({
            ModeDs: [
                { Name: "TCP" },
                { Name: "UDP" },
                { Name: "串口" },
            ],
            ComPortDs: [
                { Name: "COM1" },
                { Name: "COM2" },
                { Name: "COM3" },
                { Name: "COM4" },
                { Name: "COM5" },
                { Name: "COM6" },
                { Name: "COM7" },
                { Name: "COM8" },
                { Name: "COM9" },
                { Name: "COM10" },
                { Name: "COM11" },
                { Name: "COM12" },
                { Name: "COM13" },
                { Name: "COM14" },
                { Name: "COM15" },
                { Name: "COM16" },
                { Name: "COM17" },
                { Name: "COM18" },
                { Name: "COM19" },
                { Name: "COM20" },
                { Name: "COM21" },
                { Name: "COM22" },
                { Name: "COM23" },
                { Name: "COM24" },
                { Name: "COM25" },
                { Name: "COM26" },
                { Name: "COM27" },
                { Name: "COM28" },
                { Name: "COM29" },
                { Name: "COM30" },
                { Name: "COM31" },
                { Name: "COM32" },
                { Name: "COM33" },
                { Name: "COM34" },
                { Name: "COM35" },
                { Name: "COM36" },
                { Name: "COM37" },
                { Name: "COM38" },
                { Name: "COM39" },
                { Name: "COM40" }
            ],
            BaudRateDs: [
                { Name: "110" },
                { Name: "300" },
                { Name: "600" },
                { Name: "1200" },
                { Name: "2400" },
                { Name: "4800" },
                { Name: "9600" },
                { Name: "14400" },
                { Name: "19200" },
                { Name: "38400" },
                { Name: "57600" },
                { Name: "115200" },
                { Name: "128000" },
                { Name: "256000" }

            ],
            ParityDs: [
                { Name: "None" },
                { Name: "Odd" },
                { Name: "Even" },
                { Name: "Mark" },
                { Name: "Space" }
            ],
            StopBitsDs: [
                { Name: "One" },
                { Name: "OnePointFive" },
                { Name: "Two" }
            ],
            Mode_Chnge: function () {
                var Mode = viewModelJbxx.m.Mode;

                var IsIP = Mode == "TCP" || Mode == "UDP";

                if (IsIP) {
                    myWindow.find("#divIP").show();
                    myWindow.find("#divCK").hide();
                } else {
                    myWindow.find("#divIP").hide();
                    myWindow.find("#divCK").show();
                }


            },

            mold: {
                Id: "0",
                Name: "",

                ProtocolDefineId: 0,
                ProtocolName: "",

                Mode: "TCP",
                Port: "0",

                ComPort: "",
                BaudRate: 9600,
                Parity: "None",
                DataBits: 8,
                StopBits: "One",

                HostId: 1,

            },
            ProtocolDs: [],
            m: {
            },
            IsAdd: false,
        });
        var myWindow;

        var CurrProtocolSim = {};
        function ShowProtocolSimDetail(nodedata) {
            myAjax({
                url: "/api/ProtocolSim/Detail",
                data: { Id: nodedata.id },
                success: function (r) {
                    ShowProtocolSimDetail2(r.Data)
                }
            });
        }
        function ShowProtocolSimDetail2(m) {
            CurrProtocolSim = m;

            var s = `<div style="height:5px;"></div>
<div class="flexrow divtitle">
                                                                            <div style="width:20px;"></div>
                                                                            <div style="color: #40b4e4;width:20px;">
                                                                                <i class="fa fa-circle"></i>
                                                                            </div>
                                                                            <div style="width:100px;font-weight:bold;">基本信息  </div>
                                                                            <div style="flex:1;">
                                                                                <a id="btnEdit" style="cursor:pointer;" title="修改" onclick="EditSim()"><i class="fa fa-lg fa-pencil"></i></a>

                                                                                <span style="margin-left:10px;">当前状态：${m.RunState}</span>
                                                                                <a id="btnStart" style="cursor:pointer;margin-left:10px;color:green;" title="启动" onclick="StartSim('${m.Id}')"><i class="fa fa-lg fa-play"></i></a>

                                                                                <a id="btnStop" style="cursor:pointer;margin-left:10px;color:red;" title="停止" onclick="StopSim('${m.Id}')"><i class="fa fa-lg fa-stop"></i></a>



                                                                            </div>
                                                                            <div style="width:20px;">
                                                                                  <i class="fa fa-chevron-up" onclick="updown_Click(this)"></i>
                                                                            </div>
</div>
<div id="jbxx">
<div class="flexrow">
                                                                            <div class="tdLabel75">模拟名称</div>
                                                                            <div class="tdValue">
                                                                                <input class="k-textbox" readonly="readonly" value="${m.Name}" />
                                                                            </div>
                                                                            <div style="width:20px;"></div>
</div>

<div class="flexrow">
                                                                            <div class="tdLabel75">协议名称</div>
                                                                            <div class="tdValue">
                                                                                <input class="k-textbox" readonly="readonly" value="${m.ProtocolName}" />
                                                                            </div>
                                                                            <div style="width:20px;"></div>
</div>

<div class="flexrow">
                                                                            <div class="tdLabel75">模拟方式</div>
                                                                            <div class="tdValue">
                                                                                <textarea class="k-textbox" readonly="readonly" >${m.ModeMessage}</textarea>
                                                                            </div>
                                                                            <div style="width:20px;"></div>
</div>
</div> `;
            $("#center").html(s);


        }
        function ListSimple() {
            myAjax({
                url: "/api/ProtocolDefine/List",
                success: function (r) {

                    viewModelJbxx.set("ProtocolDs", r.Data);
                }
            })
        }
        function AddSim() {
            myWindow = $("#divSimAdd");
            viewModelJbxx.IsAdd = true;
            var v = myWindow.find("#form1")
            if (!v.data("kendoValidator")) {
                v.kendoValidator(kendoValidatorOptions)
            }
            viewModelJbxx.m = Object.assign({}, viewModelJbxx.mold);
            if (viewModelJbxx.ProtocolDs.length == 0) {
                ListSimple();
            }


            myWindow.kendoWindow({
                width: "600px",
                title: "添加模拟",
                visible: false,
                modal: true,
                actions: [
                    "Close"
                ]
            }).data("kendoWindow").center().open();



            var v = myWindow.find("#form1")
            if (!v.data("kendoValidator")) {
                v.kendoValidator(kendoValidatorOptions)
            }

            viewModelJbxx.Mode_Chnge();
            kendo.bind(myWindow, viewModelJbxx);

        }
        function EditSim() {

            myWindow = $("#divSimAdd");
            viewModelJbxx.IsAdd = false


            viewModelJbxx.m = Object.assign({}, CurrProtocolSim);
            if (viewModelJbxx.ProtocolDs.length == 0) {
                ListSimple();
            }


            myWindow.kendoWindow({
                width: "600px",
                title: "修改模拟",
                visible: false,
                modal: true,
                actions: [
                    "Close"
                ]
            }).data("kendoWindow").center().open();



            var v = myWindow.find("#form1")
            if (!v.data("kendoValidator")) {
                v.kendoValidator(kendoValidatorOptions)
            }

            viewModelJbxx.Mode_Chnge();
            kendo.bind(myWindow, viewModelJbxx);



        }
        function DeleteSim() {
            var tv = $("#treeview").data("kendoTreeView");
            var di = treeView.dataItem(treeView.select());
            if (!di) {
                return;
            }

            myConfirm({
                message: `确定要删除 模拟： ${di.Name} 吗？`,
                done: function () {
                    myAjax({
                        url: "/api/ProtocolSim/Delete",
                        data: di.toJSON(),
                        success: function (r) {
                            GetTree();
                        }
                    })
                }
            });

        }

        function SimSave() {

            var v = myWindow.find("#form1").data("kendoValidator");
            if (v.validate() == false) return;

            var data = viewModelJbxx.m;
            if (data.toJSON) {
                data = data.toJSON();
            }
            var url = "/api/ProtocolSim/Add";
            if (!viewModelJbxx.IsAdd) {
                url = "/api/ProtocolSim/Edit";
            }
            myAjax({
                url: url,
                data: data,
                success: function (r) {
                    myWindow.data("kendoWindow").close();
                    GetTree(r.Data.Id)
                }
            })

        }

        function StartSim(id) {
            url = "/api/ProtocolSim/StartSim";
            myAjax({
                url: url,
                data: { Id: id },
                success: function (r) {
                  
                    GetTree(r.Data.Id)
                }
            })
        }
        function StopSim(id) {
            url = "/api/ProtocolSim/StopSim";
            myAjax({
                url: url,
                data: { Id: id },
                success: function (r) {

                    GetTree(r.Data.Id)
                }
            })
        }
    </script>





    <!--显示主机-->
    <script>
        var CurrData = {};
        function ShowProtocolSimHostDetail(nodedata) {
            myAjax({
                url: "/api/ProtocolSimHost/Detail",
                data: { Id: nodedata.id },
                success: function (r) {
                    ShowProtocolSimHostDetail2(r.Data)
                }
            });
        }
        function ShowProtocolSimHostDetail2(m) {
            CurrData = m;


            var s = ` 

            <div style="height:10px;"></div>
<div class="flexrow divtitle">
                                                                            <div style="width:20px;"></div>
                                                                            <div style="color: #40b4e4;width:20px;">
                                                                                <i class="fa fa-circle"></i>
                                                                            </div>
                                                                            <div style="width:100px;font-weight:bold;">基本信息  </div>
                                                                            <div style="flex:1;">
                                                                                <a id="btnEdit" style="cursor:pointer;" title="修改" onclick="EditHost()"><i class="fa fa-lg fa-pencil"></i></a>

                                                                                
                                                                            </div>
                                                                            <div style="width:20px;">
                                                                                  <i class="fa fa-chevron-up" onclick="updown_Click(this)"></i>
                                                                            </div>
</div>
<div id="jbxx">
<div class="flexrow">
                                                                            <div class="tdLabel75">机号</div>
                                                                            <div class="tdValue">
                                                                                <input class="k-textbox" readonly="readonly" value="${m.HostId}" />
                                                                            </div>
                                                                            <div style="width:20px;"></div>
</div>

</div>


`;


            for (var i = 0; i < CurrData.GDSJ.length; i++) {

                s += `<div class="flexrow divtitle">
                                                                            <div style="width:20px;"></div>
                                                                            <div style="color: #40b4e4;width:20px;">
                                                                                <i class="fa fa-circle"></i>
                                                                            </div>
                                                                            <div style="width:100px;font-weight:bold;">${CurrData.GDSJ[i].Name}</div>
                                                                            <div style="flex:1;">
                                                                              ${GetGDSJMemo(CurrData.GDSJ[i])}
                                                                            </div>

                                                                             <div style="width:80px;">

                                                                                 <i class="fa fa-upload" title="导入" onclick="DRGD(${i})"></i>


                                                                                 <i class="fa fa-download" title="导出" onclick="DCGD(${i})" style="margin-left:20px;"></i>



                                                                            </div>

                                                                            <div style="width:20px;">
                                                                               <i class="fa fa-chevron-up" onclick="updown_Click(this)"></i>
                                                                            </div>
</div>
<div>
`;
                for (var j = 0; j < CurrData.GDSJ[i].Data.length; j++) {
                    s += `<div class="flexrow"  >
                                                                 <div class="tdLabel75">
                                                                 ${CurrData.GDSJ[i].Data[j].PropName}
                                                                 </div>
                                                                 <div class="tdValue">
                                                                     <input
                                                                     id="ZSB_${i}_${j}"
                                                                     value="${CurrData.GDSJ[i].Data[j].Value}" />
                                                                 </div>

                                                                 <div style="width:20px;">

                                                                </div>
                                           </div> `;
                }
                s += `
</div>`;
            }









            for (var i = 0; i < CurrData.XHSJ.length; i++) {

                s += `<div class="flexrow divtitle">
                                                                            <div style="width:20px;"></div>
                                                                            <div style="color: #40b4e4;width:20px;">
                                                                                <i class="fa fa-circle"></i>
                                                                            </div>
                                                                            <div style="width:100px;font-weight:bold;">${CurrData.XHSJ[i].Name}</div>
                                                                            <div style="flex:1;">
                                                                              ${GetXHSJMemo(CurrData.XHSJ[i])}
                                                                            </div>
                                                                           <div style="width:60px;">

                                                                                 <i class="fa fa-upload" title="导入" onclick="DRXH(${i})"></i>


                                                                                 <i class="fa fa-download" title="导出" onclick="DCXH(${i})" style="margin-left:20px;"></i>



                                                                           </div>

                                                                            <div style="width:20px;">
                                                                               <i class="fa fa-chevron-up" onclick="updown_Click(this)"></i>
                                                                            </div>
</div>
<div  style="max-height:350px;overflow-y:auto;">
`;
                //标题
                s += `<div class="flexrow"  >
                                            <div class="tdLabel75"></div>
                                            `
                for (var j = 0; j < CurrData.XHSJ[i].Data.length; j++) {
                    s += `<div class="tdValue">${CurrData.XHSJ[i].Data[j].PropName}</div>`;
                }
                s += `</div>`;


                for (var j = 0; j < CurrData.XHSJ[i].PropValue.length; j++) {
                    s += `<div class="flexrow"  >
<div class="tdLabel75">${j + 1}</div>`

                    for (var k = 0; k < CurrData.XHSJ[i].Data.length; k++) {
                        s += `<div class="tdValue"> <input  id="SB_${i}_${j}_${k}"  /></div>`;
                    }
                    s += `</div>`;
                }


                s += `
</div>`;
            }





            $("#center").html(s);


                 
            



            for (var i = 0; i < CurrData.GDSJ.length; i++) {
                for (var j = 0; j < CurrData.GDSJ[i].Data.length; j++) {

                    var o = CurrData.GDSJ[i].Data[j];
                    var mPropValue = CurrData.GDSJ[i].PropValue[j];
                    var inpuid = `ZSB_${i}_${j}`;
                    switch (o.PropType) {
                        case "值":
                        case "精度":
                        case "上限":
                        case "下限":
                            var ddl = $("#" + inpuid).kendoNumericTextBox({
                                max: 65535,
                                min: 0,
                                format: "0",
                                value: mPropValue.NumValue,
                                change: function (e) {
                                    var v = this.value();
                                    var id = e.sender.element.attr("id");
                                    var arr = id.split('_');
                                    SaveGdData(arr[1], arr[2], this.value())
                                }
                            }).data("kendoNumericTextBox");

                        default:
                            var sjzd = FindSJZD(o.SJZDKey);
                            if (sjzd) {
                                var ddl = $("#" + inpuid).kendoDropDownList({
                                    autoBind: false,
                                    dataTextField: "Name",
                                    dataValueField: "Name",
                                    value: mPropValue.StrValue,
                                    dataSource: {
                                        data: sjzd.Data
                                    },
                                    change: function (e) {
                                        var v = this.value();

                                        var id = e.sender.element.attr("id");
                                        var arr = id.split('_');
                                        SaveGdData(arr[1], arr[2], this.value())
                                    }
                                }).data("kendoDropDownList");

                            }
                            break;
                    }
                }
            }


            for (var i = 0; i < CurrData.XHSJ.length; i++) {
                for (var j = 0; j < CurrData.XHSJ[i].PropValue.length; j++) {
                    for (var k = 0; k < CurrData.XHSJ[i].Data.length; k++) {
                        var o = CurrData.XHSJ[i].Data[k];
                        var mPropValue = CurrData.XHSJ[i].PropValue[j][k];

                        var inpuid = `SB_${i}_${j}_${k}`;
                        switch (o.PropType) {
                            case "值":
                            case "精度":
                            case "上限":
                            case "下限":
                                var ddl = $("#" + inpuid).kendoNumericTextBox({
                                    max: 65535,
                                    min: 0,
                                    format: "0",
                                    value: mPropValue.NumValue,
                                    change: function (e) {
                                        var v = this.value();
                                        var id = e.sender.element.attr("id");
                                        var arr = id.split('_');
                                        SaveXhData(arr[1], arr[2], arr[3], this.value())
                                    }
                                }).data("kendoNumericTextBox");

                            default:
                                var sjzd = FindSJZD(o.SJZDKey);
                                if (sjzd) {
                                    var ddl = $("#" + inpuid).kendoDropDownList({
                                        autoBind: false,
                                        dataTextField: "Name",
                                        dataValueField: "Name",
                                        value: mPropValue.StrValue,
                                        dataSource: {
                                            data: sjzd.Data
                                        },
                                        change: function (e) {
                                            var v = this.value();

                                            var id = e.sender.element.attr("id");
                                            var arr = id.split('_');
                                            SaveXhData(arr[1], arr[2], arr[3], this.value())
                                        }
                                    }).data("kendoDropDownList");

                                }
                                break;
                        }
                    }
                }
            }

        }


        function GetGDSJMemo(m) {
            var s = `功能码：${m.Gnm} 开始地址:${m.StartAddress} `
            if (m.BitData) {
                s += ` 比特数据 `;
            }

            s += ` 数据数量:${m.ReqNum}  `;


            return s;
        }

        function GetXHSJMemo(m) {
            var s = `功能码：${m.Gnm} 开始地址:${m.StartAddress} `
            if (m.BitData) {
                s += ` 比特数据 `;
            }

            s += ` 每组数据数量:${m.ReqNum}  `;

            return s;
        }

        function FindSJZD(name) {
            for (var i = 0; i < CurrData.SJZD.length; i++) {
                if (CurrData.SJZD[i].Name == name) {
                    return CurrData.SJZD[i];
                }
            }
            return null;
        }
        function FindSJZDValue(data, name) {

            for (var i = 0; i < data.length; i++) {

                if (data[i].Name == name) {
                    return data[i];
                }
            }
            return null;
        }

        function SaveGdData(i, j, s) {
            
             
            var data = {
                Id: CurrData.Id,
                I: i,
                J: j,
                StrValue: s
            };
            myAjax({
                url: "/api/ProtocolSimHost/SaveGdData",
                data: data,
                success: function (r) {
                    CurrData.GDSJ[i].PropValue[j] = r.Data.GDSJ[i].PropValue[j];


                }
            })

        }
        function SaveXhData(i, j, k, s) {
            var data = {
                Id: CurrData.Id,
                I: i,
                J: j,
                K: k,
                StrValue: s
            };
            myAjax({
                url: "/api/ProtocolSimHost/SaveXhData",
                data: data,
                success: function (r) {

                    CurrData.XHSJ[i].PropValue[j][k] = r.Data.XHSJ[i].PropValue[j][k];

                }
            })

        }

        
        function gridLogPage() {
             
              
            
        }
    </script>



    <!--导入固定数据-->
    <div id="divGDDR" style="display: none; max-height: 90.740160vh !important; overflow-y: auto; ">



        <div id="grid" style="height: 34.351632vh !important; "></div>


        <div style="height:20px;">

        </div>

        <div class="flexrow">
            <div style="flex:1;"></div>
            <div style="width:100px;">
                <input type="file" id="fileInputGD" style="display:none;" accept=".xlsx" />
                <a id="btnImport" class="k-button"
                   style="cursor:pointer;margin-left:10px;" title="导入"
                   onclick="document.getElementById('fileInputGD').click()"><i class="fa fa-lg fa-upload"></i>导入</a>

            </div>



            <div style="width:100px;">
                <a id="btnOK" href="javascript:ImportGD();" class="k-button k-primary" style="width:80px;display: none;" accesskey="S">

                    <span style="text-decoration:underline;">S</span>
                    确定
                </a>
            </div>

            <div style="width:100px;">
                <a href="javascript:;" onclick="closeWindow(this);" class="k-button" style="width:80px;" accesskey="C">

                    <span style="text-decoration:underline;">C</span>
                    取消
                </a>
            </div>

            <div style="flex:1;"></div>
        </div>
    </div>
    <script>
        function DRGD(i) {
            currdrData = CurrData.GDSJ[i]
            myWindow = $("#divGDDR");
            myWindow.kendoWindow({
                width: "600px",
                title: `导入${currdrData.Name}`,
                visible: false,
                modal: true,
                actions: [
                    "Close"
                ]
            }).data("kendoWindow").center().open();

            var v = myWindow.find("#grid")
            if (!v.data("kendoGrid")) {

                var opt = Object.assign({}, gridBaseOption);

                opt.columns = [
                    { title: '属性名字', field: "PropName", width: 50, sortable: false, filterable: false, },
                    { title: '值', field: "StrValue", width: 50, sortable: false, filterable: false, },


                ]
                var grid = myWindow.find("#grid").kendoGrid(opt).data("kendoGrid");
            }
            document.getElementById('fileInputGD').value = "";

        }
        // 添加文件读取功能
        document.getElementById('fileInputGD').addEventListener('change', function (e) {
            myWindow.find("#btnOK").hide();
            var file = e.target.files[0];
            if (!file) return;

            var reader = new FileReader();
            reader.onload = function (e) {
                try {
                    var data = new Uint8Array(e.target.result);
                    var workbook = XLSX.read(data, { type: 'array' });
                    var firstSheetName = workbook.SheetNames[0];
                    var worksheet = workbook.Sheets[firstSheetName];
                    var json = XLSX.utils.sheet_to_json(worksheet, {
                        header: 1,  // 使用数组格式
                        defval: "", // 空单元格默认值
                        raw: false, // 处理公式和格式
                        blankrows: false // 包含空行
                    });
                    document.getElementById('fileInputGD').value = "";

                    if (json.length < currdrData.Data.length + 1) {
                        myAlert("数据行数错误！")
                        return;
                    }

                    var griddata = []
                    for (var i = 1; i < currdrData.Data.length + 1; i++) {
                        var o = currdrData.Data[i - 1]
                        if (json[i].length < 2) {
                            myAlert(`第${i + 1}行数据格式错误`)
                            return;
                        }

                        var PropName = json[i][0];
                        var StrValue = json[i][1];
                        if (o.PropName != PropName) {
                            myAlert(`第${i + 1}行数据应该是：${o.PropName}`)
                            return;
                        }
                        switch (o.PropType) {
                            case "值":
                            case "精度":
                            case "上限":
                            case "下限":
                                if (isNaN(StrValue)) {
                                    myAlert(`第${i + 1}行数据应该是数字`);
                                    return;
                                }
                                break;
                            default:
                                var sjzd = FindSJZD(o.SJZDKey);

                                if (FindSJZDValue(sjzd.Data, StrValue) == null) {
                                    myAlert(`第${i + 1}行数据未能找到对应字典：${StrValue}`)
                                    return;
                                }
                                break;
                        }
                        griddata.push({
                            Id: i,
                            PropName: json[i][0],
                            StrValue: json[i][1],
                        })
                    }


                    var grid = myWindow.find("#grid").data("kendoGrid");
                    var dsoptions = {
                        schema: {
                            model: {
                                id: "Id",
                                fields: { Id: { editable: false, nullable: true } }
                            }
                        },
                        data: griddata,
                    };
                    var gridDataSource = new kendo.data.DataSource(dsoptions);
                    grid.setDataSource(gridDataSource);
                    gridDataSource.read();

                    myWindow.find("#btnOK").show();
                }
                catch (error) {
                    myAlert("格式错误：" + error)
                }

            };
            reader.readAsArrayBuffer(file);
        });

        function ImportGD() {

            var data = {
                Id: CurrData.Id,
                I: 0,
                J: 0,
                StrValue: []
            };
            var i = 0;
            for (i = 0; i < CurrData.GDSJ.length; i++) {
                if (CurrData.GDSJ[i].Id == currdrData.Id) {
                    break;
                }
            }
            data.I = i;

            var grid = myWindow.find("#grid").data("kendoGrid");
            var gridData = grid.dataSource.data();
            for (var i = 0; i < gridData.length; i++) {
                data.StrValue.push(gridData[i].StrValue);
            }

            myAjax({
                url: "/api/ProtocolSimHost/ImportGD",
                data: data,
                success: function (r) {
                    myWindow.data("kendoWindow").close();
                    GetTree(CurrData.Id);
                }
            })

        }


        function DCGD(i) {
            // 获取数据
            var data = CurrData.GDSJ[i]

            // 创建工作表数据
            var wsData = [
                ["属性名称", "值"] // 表头
            ];

            for (var i = 0; i < data.Data.length; i++) {
                var o = data.Data[i]
                var pv = data.PropValue[i];
                wsData.push([
                    o.PropName || "",
                    pv.StrValue || "",
                ]);
            }


            // 创建工作表
            var ws = XLSX.utils.aoa_to_sheet(wsData);

            // 创建工作簿
            var wb = XLSX.utils.book_new();
            XLSX.utils.book_append_sheet(wb, ws, "Sheet1");

            // 导出文件
            XLSX.writeFile(wb, `${data.Name}.xlsx`);
        }
    </script>






    <!--导入循环数据-->
    <div id="divXHDR" style="display: none; max-height: 90.740160vh !important; overflow-y: auto; ">


        <div id="divgrid">
            <div id="grid" style="height: 64.351632vh !important; "></div>
        </div>



        <div style="height:20px;">

        </div>

        <div class="flexrow">
            <div style="flex:1;"></div>
            <div style="width:100px;">
                <input type="file" id="fileInputXH" style="display:none;" accept=".xlsx" />
                <a id="btnImportXH" class="k-button"
                   style="cursor:pointer;margin-left:10px;" title="导入"
                   onclick="document.getElementById('fileInputXH').click()"><i class="fa fa-lg fa-upload"></i>导入</a>

            </div>



            <div style="width:100px;">
                <a id="btnOK" href="javascript:ImportXH();" class="k-button k-primary" style="width:80px;display: none;" accesskey="S">

                    <span style="text-decoration:underline;">S</span>
                    确定
                </a>
            </div>

            <div style="width:100px;">
                <a href="javascript:;" onclick="closeWindow(this);" class="k-button" style="width:80px;" accesskey="C">

                    <span style="text-decoration:underline;">C</span>
                    取消
                </a>
            </div>

            <div style="flex:1;"></div>
        </div>
    </div>
    <script>

        function DRXH(i) {
            currdrData = CurrData.XHSJ[i]
            myWindow = $("#divXHDR");
            myWindow.kendoWindow({
                width: "1200px",
                title: `导入${currdrData.Name}`,
                visible: false,
                modal: true,
                actions: [
                    "Close"
                ]
            }).data("kendoWindow").center().open();

            var v = myWindow.find("#grid")
            if (v.data("kendoGrid")) {
                var grid = myWindow.find("#grid").data("kendoGrid");
                grid.destroy();
                v.remove();
                myWindow.find("#divgrid").html(` <div id="grid" style="height: 64.351632vh !important; "></div>`);

            }
            if (!v.data("kendoGrid")) {

                var opt = Object.assign({}, gridBaseOption);
                opt.columns = [
                    { title: '编号', field: "Id", width: 50, sortable: false, filterable: false, }

                ]

                for (var i = 0; i < currdrData.Data.length; i++) {

                    opt.columns.push({
                        title: currdrData.Data[i].PropName, field: currdrData.Data[i].PropName, width: 50, sortable: false, filterable: false,
                    })
                }

                var grid = myWindow.find("#grid").kendoGrid(opt).data("kendoGrid");
            }
            document.getElementById('fileInputXH').value = "";

        }
        // 添加文件读取功能
        document.getElementById('fileInputXH').addEventListener('change', function (e) {
            myWindow.find("#btnOK").hide();
            var file = e.target.files[0];
            if (!file) return;

            var reader = new FileReader();
            reader.onload = function (e) {
                try {
                    var data = new Uint8Array(e.target.result);
                    var workbook = XLSX.read(data, { type: 'array' });
                    var firstSheetName = workbook.SheetNames[0];
                    var worksheet = workbook.Sheets[firstSheetName];
                    var json = XLSX.utils.sheet_to_json(worksheet, {
                        header: 1,  // 使用数组格式
                        defval: "", // 空单元格默认值
                        raw: false, // 处理公式和格式
                        blankrows: false // 包含空行
                    });
                    document.getElementById('fileInputGD').value = "";

                    if (json.length < 2) {
                        myAlert("数据行数错误！")
                        return;
                    }

                    var griddata = []
                    for (var ir = 1; ir < json.length; ir++) {
                        var rowdata = json[ir];
                        var gridrowdata = {
                            Id: ir
                        };
                        if (rowdata.length < currdrData.length) {
                            myAlert(`第${ir + 1}行数据格式错误`)
                            return;
                        }
                        for (var i = 0; i < currdrData.Data.length; i++) {
                            var o = currdrData.Data[i]
                            var StrValue = rowdata[i];
                            switch (o.PropType) {
                                case "值":
                                case "精度":
                                case "上限":
                                case "下限":
                                    if (isNaN(StrValue)) {
                                        myAlert(`第${ir + 1}行  ${o.PropName} 数据应该是数字 ：${StrValue || ""}`);
                                        return;
                                    }
                                    break;
                                default:
                                    var sjzd = FindSJZD(o.SJZDKey);

                                    if (FindSJZDValue(sjzd.Data, StrValue) == null) {
                                        myAlert(`第${ir + 1}行  ${o.PropName}  数据未能找到对应字典：${StrValue}`)
                                        return;
                                    }
                                    break;
                            }

                            gridrowdata[o.PropName] = StrValue;
                        }
                        griddata.push(gridrowdata)
                    }


                    var grid = myWindow.find("#grid").data("kendoGrid");
                    var dsoptions = {
                        schema: {
                            model: {
                                id: "Id",
                                fields: { Id: { editable: false, nullable: true } }
                            }
                        },
                        data: griddata,
                    };
                    var gridDataSource = new kendo.data.DataSource(dsoptions);
                    grid.setDataSource(gridDataSource);
                    gridDataSource.read();

                    myWindow.find("#btnOK").show();
                }
                catch (error) {
                    myAlert("格式错误：" + error)
                }

            };
            reader.readAsArrayBuffer(file);
        });

        function ImportXH() {

            var data = {
                Id: CurrData.Id,

                StrValue: []
            };
            var i = 0;
            for (i = 0; i < CurrData.XHSJ.length; i++) {
                if (CurrData.XHSJ[i].Id == currdrData.Id) {
                    break;
                }
            }
            data.I = i;

            var grid = myWindow.find("#grid").data("kendoGrid");
            var gridData = grid.dataSource.data();
            for (var ir = 0; ir < gridData.length; ir++) {
                var rowdata = [];
                var gridRowData = gridData[ir];
                for (var i = 0; i < currdrData.Data.length; i++) {
                    var o = currdrData.Data[i]
                    rowdata.push(gridRowData[o.PropName]);

                    //rowdata.push(gridData[ir][o.PropName]);
                }
                data.StrValue.push(rowdata);
            }


            myAjax({
                url: "/api/ProtocolSimHost/ImportXH",
                data: data,
                success: function (r) {
                    myWindow.data("kendoWindow").close();
                    GetTree(CurrData.Id);
                }
            })

        }
        function DCXH(i) {
            // 获取数据
            var data = CurrData.XHSJ[i]

            var wsData = [];

            var rowData = [];
            for (var i = 0; i < data.Data.length; i++) {
                var o = data.Data[i];

                rowData.push(o.PropName || "")
            }
            wsData.push(rowData);

            for (var i = 0; i < data.PropValue.length; i++) {
                var row = data.PropValue[i];

                var rowData = [];
                for (var j = 0; j < data.Data.length; j++) {
                    //                    var o = data.Data[j];
                    rowData.push(row[j].StrValue || "")
                }
                wsData.push(rowData);
            }

            // 创建工作表
            var ws = XLSX.utils.aoa_to_sheet(wsData);

            // 创建工作簿
            var wb = XLSX.utils.book_new();
            XLSX.utils.book_append_sheet(wb, ws, "Sheet1");

            // 导出文件
            XLSX.writeFile(wb, `${data.Name}.xlsx`);
        }
    </script>












    <!--添加Host-->
    <div id="divHostAdd" style="display:none;">
        <form id="form1"> 
            <div class="flexrow"  >
                <div class="tdLabel75">主机号</div>
                <div class="tdValue">

                    <input id="HostId" style="width:150px;"
                           data-role="numerictextbox"
                           data-min="1"
                           data-max="255"
                           data-format="N0"
                           data-bind="value:m.HostId" />

                </div>
                <div style="width:20px;"></div>
            </div>

        </form>


        <div style="height:20px;">

        </div>

        <div class="flexrow">
            <div style="flex:1;"></div>
            <div style="width:100px;">
                <a href="javascript:HostSave();" class="k-button" style="width:80px;" accesskey="S">

                    <span style="text-decoration:underline;">S</span>
                    确定
                </a>
            </div>

            <div style="width:100px;">
                <a href="javascript:;" onclick="closeWindow(this);" class="k-button" style="width:80px;" accesskey="C">

                    <span style="text-decoration:underline;">C</span>
                    取消
                </a>
            </div>

            <div style="flex:1;"></div>
        </div>
    </div>
    <script>
        var viewModelHost = new kendo.data.ObservableObject({
           
            mold: {
                Id: "0",
                Name: "",

                ProtocolSimId: 0,
                HostId: 1,
                HostName: "",
 

            },
          
            m: {
            },
            IsAdd: false,
        });
        var myWindow;

        var CurrProtocolSimHost = {};
         
        function AddHost(pdata) {
             
            myWindow = $("#divHostAdd");
            viewModelHost.IsAdd = true;
            var v = myWindow.find("#form1")
            if (!v.data("kendoValidator")) {
                v.kendoValidator(kendoValidatorOptions)
            }
            viewModelHost.m = Object.assign({}, viewModelHost.mold);
            viewModelHost.m.ProtocolSimId = pdata.id;
           
            myWindow.kendoWindow({
                width: "600px",
                title: "添加模拟主机",
                visible: false,
                modal: true,
                actions: [
                    "Close"
                ]
            }).data("kendoWindow").center().open();



            var v = myWindow.find("#form1")
            if (!v.data("kendoValidator")) {
                v.kendoValidator(kendoValidatorOptions)
            }
             
            kendo.bind(myWindow, viewModelHost);

        }
        function EditHost() {

            myWindow = $("#divHostAdd");
            viewModelHost.IsAdd = false


            viewModelHost.m = Object.assign({}, viewModelHost.mold);
            viewModelHost.m.Id = CurrData.Id;
            viewModelHost.m.HostId = CurrData.HostId;
             


            myWindow.kendoWindow({
                width: "600px",
                title: "修改模拟主机",
                visible: false,
                modal: true,
                actions: [
                    "Close"
                ]
            }).data("kendoWindow").center().open();



            var v = myWindow.find("#form1")
            if (!v.data("kendoValidator")) {
                v.kendoValidator(kendoValidatorOptions)
            }
             
            kendo.bind(myWindow, viewModelHost);



        }
        function DeleteHost() {
            var tv = $("#treeview").data("kendoTreeView");
            var di = treeView.dataItem(treeView.select());
            if (!di) {
                return;
            }

            myConfirm({
                message: `确定要删除 模拟： ${di.text} 吗？`,
                done: function () {
                    myAjax({
                        url: "/api/ProtocolSimHost/Delete",
                        data: di.toJSON(),
                        success: function (r) {
                            GetTree();
                        }
                    })
                }
            });

        }

        function HostSave() {

            var v = myWindow.find("#form1").data("kendoValidator");
            if (v.validate() == false) return;

            var data = viewModelHost.m;
            if (data.toJSON) {
                data = data.toJSON();
            }
            var url = "/api/ProtocolSimHost/Add";
            if (!viewModelHost.IsAdd) {
                url = "/api/ProtocolSimHost/Edit";
            }
            myAjax({
                url: url,
                data: data,
                success: function (r) {
                    myWindow.data("kendoWindow").close();
                    GetTree(r.Data.Id)
                }
            })

        }
    </script>




    <script>
        var SizeInfo;
        $(function () {

            kendo.culture("zh-CN");


            if (window.Init) {
                Init();
            }
        });
        function After50(d) {
            if (d) {
                setTimeout(function () { d(); }, 50);
            }
        }
    </script>
</body>
</html>
